<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            position: relative;
            width: 350px;
            height: 30px;
            margin: auto;
            border: 1px solid green;
        }
        input{
            width: 320px;
            height: 30px;
            border: none;
            
        }
        input[type="password"]::-ms-reveal{
            display: none;
        }
        img{
            float: right;
            width: 30px;
            height: 30px;
            
        }
    </style>
</head>
<body>
    <div class="box">
            <img src="bi.jpg" alt="" id="eye">
        <input type="password" name="" id="pwd" placeholder="请输入密码">
    </div>
    <script>
        const input=document.getElementById('pwd');
        const img=document.getElementById('eye');

        let pwdshown=false;

        img.addEventListener('click',function(){
            pwdshown=!pwdshown;
            if(pwdshown){
                img.src="zheng.jpg";
                input.type='text';    
            }else{
                img.src="bi.jpg"
                input.type='password';
            }
        });
    </script>


<!-- <label for="pwd1"></label>
    <input type="password" id="pwd1"/>
    <input type="checkbox" id="pwd2"/>
    <label for="pwd2"></label>
    <script>
        const input=document.getElementById('pwd1');
        const input2=document.getElementById('pwd2');
        input2.addEventListener('change',function(){
            if(this.checked){
                input.type='text';
            }else{
                input.type='password';
            }
        })
    </script> -->
</body>
</html>